<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.products_listings.php 433 2014-01-19 11:46:57Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 433 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-19 11:46:57 +0000 (Sun, 19 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction('getListData');
$xajax->registerFunction('saveValues');

function getListData($name = '') {
	global $db;

	$ajax = new xajaxResponse();
	
	$selected = '';
	
	$cols[] = array('id' => '0', 'text' => MANY_COLS);
	$cols[] = array('id' => '1', 'text' => '1');
	$cols[] = array('id' => '2', 'text' => '2');
	$cols[] = array('id' => '3', 'text' => '3');
	$cols[] = array('id' => '4', 'text' => '4');
	
	$count[] = array('id' => '1', 'text' => '1');
	$count[] = array('id' => '5', 'text' => '5');
	$count[] = array('id' => '10', 'text' => '10');
	$count[] = array('id' => '30', 'text' => '30');
	
	$slider[] = array('id' => 'none', 'text' => NO);
	$slider[] = array('id' => 'slider', 'text' => 'slider');
	$slider[] = array('id' => 'fader', 'text' => 'fader');
	
	$direction[] = array('id' => 'up', 'text' => 'hoch');
	$direction[] = array('id' => 'down', 'text' => 'runter');
	$direction[] = array('id' => 'left', 'text' => 'links');
	$direction[] = array('id' => 'right', 'text' => 'rechts');
	
	if(!empty($name)) {
		$options_data = $db->db_query("SELECT
											list_name,
											col,
											p_img,
											p_name,
											p_price,
											b_details,
											b_order,
											b_wishlist,
											p_reviews,
											p_stockimg,
											p_vpe,
											p_model,
											p_isbn,
											p_manu_img,
											p_manu_name,
											p_short_desc,
											p_short_desc_lenght,
											p_long_desc,
											p_long_desc_lenght,
											list_type,
											list_file,
											box_count,
											box_effect,
											effect_direction
										FROM
											".TABLE_PRODUCTS_LISTINGS."
										WHERE
											list_name = '".$name."'");

		$c .= '<h1>'.trim(constant(strtoupper($options_data->fields['list_name']).'_TITLE')).'</h1>';
		$c .= '<form id="listing_options_form" name="listing_options_form">';
		$c .= '	<table width="100%">
					<tr>
						<td width="33.3%" valign="top">
							<table width="100%">';
							if($options_data->fields['list_type']!='box') {
								$c .= '<tr>
										<td class="main">'.COLS.'</td>
										<td class="main">'.draw_pull_down_menu('col', $cols, $options_data->fields['col'], 'style="width:40px"').'</td>
									</tr>';
							} else {
								$c .= draw_hidden_field('col', 1, $options_data->fields['col']);
								if($options_data->fields['box_count'] !=0) {
									$c .= '<tr>
												<td class="main">'.BOX_COUNT.'</td>
												<td class="main">'.draw_pull_down_menu('box_count', $count, $options_data->fields['box_count']).'</td>
											</tr>';
								}
								$c .= ' <tr>
											<td class="main">'.BOX_EFFECT.'</td>
											<td class="main">'.draw_pull_down_menu('box_effect', $slider, $options_data->fields['box_effect']).'</td>
										</tr>
										<tr>
											<td class="main">'.EFFECT_DIRECTION.'</td>
											<td class="main">'.draw_pull_down_menu('effect_direction', $direction, $options_data->fields['effect_direction']).'</td>
										</tr>';
							}
							$c .= '<tr>
									<td class="main">'.NAME.'</td>
									<td class="main">'.draw_selection_field('p_name', 'checkbox', '1',$options_data->fields['p_name']==1 ? true : false).'</td>
								</tr>
								<tr>
									<td class="main">'.PICTURE.'</td>
									<td class="main">'.draw_selection_field('p_img', 'checkbox', '1',$options_data->fields['p_img']==1 ? true : false).'</td>
								</tr>
								<tr>
									<td class="main">'.PRICE.'</td>
									<td class="main">'.draw_selection_field('p_price', 'checkbox', '1',$options_data->fields['p_price']==1 ? true : false).'</td>
								</tr>
								<tr>
									<td class="main">'.VPE_DISPLAY.'</td>
									<td class="main">'.draw_selection_field('p_vpe', 'checkbox', '1',$options_data->fields['p_vpe']==1 ? true : false).'</td>
								</tr>
							</table>
						</td>';
						
						if($options_data->fields['list_type'] !='box') {
							$file_dropdown  = '	<select name="list_file" id="list_file">';
							foreach( array(
                  array('name' => 'Standard Datei(en)', 'path' => 'product_listing', 'praefix' => ''),
                  array('name' => 'Spezielle Liste', 'path' => 'listings', 'praefix' => 'listings/')
                ) as $listItem) {
							
  							if ($dir = opendir(DIR_FS_DOCUMENT_ROOT.'templates/'.CURRENT_TEMPLATE.'/module/'.$listItem['path'].'/')) {
    							$file_dropdown .= '		<optgroup label="'.$listItem['name'].'">';

  								while (($file = readdir($dir)) !== false) {
  									$selected = '';
  									if (is_file(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/'.$listItem['path'].'/'.$file) && ($file != "index.html") && (substr($file, 0, 1) !=".")) {
  										if($listItem['praefix'].str_replace('.html', '', $file) == $options_data->fields['list_file'])
  											$selected = ' selected=""';
  										$file_dropdown .= '<option value="'.$listItem['praefix'].str_replace('.html', '', $file).'"'.$selected.'>'.$file.'</option>';
  									}
  								}
  								closedir($dir);
   								$file_dropdown .= '		</optgroup>';
                }
              }
							$file_dropdown .= '	</select>';
/*
    							if($options_data->fields['list_file'] == 'product_listing') $selected = ' selected=""';
  							$file_dropdown .= '			<option value="product_listings"'.$selected.'>product_listings.html</option>';
  							$file_dropdown .= '		</optgroup>';

							if ($dir = opendir(DIR_FS_DOCUMENT_ROOT.'templates/'.CURRENT_TEMPLATE.'/module/listings/')) {
								$file_dropdown .= '		<optgroup label="Spezielle Liste">';
								while (($file = readdir($dir)) !== false) {
									$selected = '';
									if (is_file(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/listings/'.$file) && ($file != "index.html") && (substr($file, 0, 1) !=".")) {
										if('listings/'.str_replace('.html', '', $file) == $options_data->fields['list_file'])
											$selected = ' selected=""';
										$file_dropdown .= '<option value="listings/'.str_replace('.html', '', $file).'"'.$selected.'>'.$file.'</option>';
									}	
								}
								closedir($dir);
								$file_dropdown .= '		</optgroup>';
								$file_dropdown .= '	</select>';
*/
//							}

							$c .= '
							<td width="33.3%" valign="top">
								<table width="100%">
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.DETAIL_BUTTON.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.draw_selection_field('b_details', 'checkbox', '1',$options_data->fields['b_details']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.BUY_BUTTON.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.draw_selection_field('b_order', 'checkbox', '1',$options_data->fields['b_order']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.WISHLIST_BUTTON.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.draw_selection_field('b_wishlist', 'checkbox', '1',$options_data->fields['b_wishlist']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.ARTICLE_NR.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.draw_selection_field('p_model', 'checkbox', '1',$options_data->fields['p_model']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.REVIEW.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.draw_selection_field('p_reviews', 'checkbox', '1',$options_data->fields['p_reviews']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main" style="border-left: 1px solid #ccc">'.LIST_NAME.'</td>
										<td class="main" style="border-right: 1px solid #ccc">'.$file_dropdown.'</td>
									</tr>
								</table>
							</td>
							<td width="33.3%" valign="top">
								<table width="100%">
									<tr>
										<td class="main">ISBN Nr:</td>
										<td class="main">'.draw_selection_field('p_isbn', 'checkbox', '1',$options_data->fields['p_isbn']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main">'.STOCK.'</td>
										<td class="main">'.draw_selection_field('p_stockimg', 'checkbox', '1',$options_data->fields['p_stockimg']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main">'.BRAND_IMG.'</td>
										<td class="main">'.draw_selection_field('p_manu_img', 'checkbox', '1',$options_data->fields['p_manu_img']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main">'.BRAND_NAME.'</td>
										<td class="main">'.draw_selection_field('p_manu_name', 'checkbox', '1',$options_data->fields['p_manu_name']==1 ? true : false).'</td>
									</tr>
									<tr>
										<td class="main">'.SHORT_DESC.'</td>
										<td class="main">'.draw_selection_field('p_short_desc', 'checkbox', '1',$options_data->fields['p_short_desc']==1 ? true : false).' '.draw_input_field('p_short_desc_lenght', $options_data->fields['p_short_desc_lenght'], 'size="3"').'</td>
									</tr>
									<tr>
										<td class="main">'.LONG_DESC.'</td>
										<td class="main">'.draw_selection_field('p_long_desc', 'checkbox', '1',$options_data->fields['p_long_desc']==1 ? true : false).' '.draw_input_field('p_long_desc_lenght', $options_data->fields['p_long_desc_lenght'], 'size="3"').'</td>
									</tr>
								</table>
							</td>';
						} else {
							$c .= '
							<td width="33.3%" valign="top">
								&nbsp;
							</td>
							<td width="33.3%" valign="top">
								&nbsp;
							</td>';
						}
				$c .= '</tr>
				</table>
			<input type="hidden" name="list_name" value="'.$options_data->fields['list_name'].'" />
		</form>';
		$ajax->assign('save_button', 'style.display', 'block');

	} else
		$ajax->assign('save_button', 'style.display', 'none');

	$ajax->assign('lists_data', 'innerHTML', $c);

	return $ajax;
}

function saveValues($vars) {
	global $db;

	$ajax = new xajaxResponse();
	
	$sql_data_array = array('col' => $vars['col'],
							'p_img' => $vars['p_img'],
							'p_name' => $vars['p_name'],
							'p_price' => $vars['p_price'],
							'b_details' => $vars['b_details'],
							'b_order' => $vars['b_order'],
							'b_wishlist' => $vars['b_wishlist'],
							'p_reviews' => $vars['p_reviews'],
							'p_stockimg' => $vars['p_stockimg'],
							'p_vpe' => $vars['p_vpe'],
							'p_model' => $vars['p_model'],
							'p_isbn' => $vars['p_isbn'],
							'p_manu_img' => $vars['p_manu_img'],
							'p_manu_name' => $vars['p_manu_name'],
							'p_short_desc' => $vars['p_short_desc'],
							'p_short_desc_lenght' => $vars['p_short_desc_lenght'],
							'p_long_desc' => $vars['p_long_desc'],
							'p_long_desc_lenght' => $vars['p_long_desc_lenght'],
							'list_file' => $vars['list_file'],
							'box_count' => $vars['box_count'],
							'box_effect' => $vars['box_effect'],
							'effect_direction' => $vars['effect_direction']);

	$db->db_perform(TABLE_PRODUCTS_LISTINGS, $sql_data_array, 'update', "list_name = '".$vars['list_name']."' ");
	
	$j .= '$.gritter.add({'."\n";
	$j .= '		title: \'Erfolgreich gespeichert\','."\n";
	$j .= '		text: \'Die Listeneinstellung für "'.trim(constant(strtoupper($vars['list_name']).'_TITLE')).'" wurde gespeichert.\','."\n";
	$j .= '		image: \''.DIR_WS_ICONS.'dialog-success.png\','."\n";
	$j .= '		sticky: false,'."\n";
	$j .= '		time: 3500'."\n";
	$j .= '});';

	$ajax->script($j);
	
	return $ajax;
}
?>